package com.jintoufs.weixin.wxpay;


import com.alibaba.fastjson.JSONObject;
import com.jintoufs.domain.common.WxCommon;
import com.jintoufs.domain.constants.Constants;
import com.jintoufs.domain.constants.WxConstant;
import com.jintoufs.domain.hotel.HotelOrder;
import com.jintoufs.domain.scene.SceneOrder;
import com.jintoufs.domain.sys.Dictionary;
import com.jintoufs.domain.tour.TourRouteOrder;
import com.jintoufs.domain.wxpay.PayBack;
import com.jintoufs.domain.wxpay.PayInfo;
import com.jintoufs.service.customer.CustomerService;
import com.jintoufs.service.hotel.HotelOrderService;
import com.jintoufs.service.scene.SceneOrderService;
import com.jintoufs.service.sys.DictionaryService;
import com.jintoufs.service.tour.TourRouteOrderService;
import com.jintoufs.service.weixin.WxPayService;
import com.jintoufs.service.weixin.WxRefundService;
import com.jintoufs.util.valid.ValidUtil;
import com.jintoufs.util.weixin.HttpResult;
import com.jintoufs.util.weixin.HttpUtil;
import com.jintoufs.util.weixin.RandomUtils;
import com.jintoufs.util.weixin.TimeUtils;
import com.jintoufs.weixin.SupportAction;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

@Controller
@Scope("prototype")
@RequestMapping("/api/wxpay")
public class PayAction extends SupportAction {

    private static Logger log = Logger.getLogger(PayAction.class);

    @Resource
    private SceneOrderService sceneOrderService;
    @Resource
    private HotelOrderService hotelOrderService;

    @Resource
    private TourRouteOrderService tourRouteOrderService;

    @Resource
    private WxPayService wxPayService;

    @Resource
    CustomerService customerService;

    @Resource
    DictionaryService dictionaryService;
    @Resource
    private WxRefundService refundService;

//    @Value("smsAppid")
//    private int smsAppid;
//    @Value("smsAppkey")
//    private String smsAppkey;

    @ResponseBody
    @GetMapping(value = "/prepay")
    public AjaxMsg prePay(String code, String orderId, String orderType, String openId, HttpServletRequest request) {
        AjaxMsg ajaxMsg = new AjaxMsg();
        Map<String, Object> map = new HashMap<>();
        ObjectMapper mapper = new ObjectMapper();
        boolean result = true;
        String info = "";
        try {
            openId = getOpenId(code);
            if (StringUtils.isBlank(openId)) {
                result = false;
                info = "获取到openId为空";
            } else {
                String clientIP = WxCommon.getClientIp(request);
                log.error("openId: " + openId + ", clientIP: " + clientIP);
                String randomNonceStr = RandomUtils.generateMixString(32);
                String prepayId = unifiedOrder(openId, clientIP, randomNonceStr, orderId, orderType);
                log.error("prepayId: " + prepayId);
                if (StringUtils.isBlank(prepayId)) {
                    result = false;
                    info = "出错了，未获取到prepayId";
                    throw new RuntimeException("预下单失败");
                } else {
                    map.put("prepayId", prepayId);
                    map.put("nonceStr", randomNonceStr);
                }
            }
            map.put("result", result);
            map.put("info", info);
            ajaxMsg.setDatas(map);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxMsg.setCode(AjaxMsg.FAILURE);
            ajaxMsg.setMessage(info);
            return ajaxMsg;
        }
        return ajaxMsg;
    }


    private String getOpenId(String code) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + WxConstant.APP_ID +
                "&secret=" + WxConstant.APP_SECRET + "&js_code=" + code + "&grant_type=authorization_code";

        HttpUtil httpUtil = new HttpUtil();
        try {

            HttpResult httpResult = httpUtil.doGet(url, null, null);

            if (httpResult.getStatusCode() == 200) {

                JSONObject obj = JSONObject.parseObject(httpResult.getBody());

                log.error("getOpenId: " + obj.toString());

                if (obj.get("errcode") != null) {
                    log.error("getOpenId returns errcode: " + obj.get("errcode"));
                    return "";
                } else {
                    return obj.get("openid").toString().replaceAll("\"", "");
                }
                //return httpResult.getBody();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 调用统一下单接口
     *
     * @param openId         openId
     * @param clientIP       用户IP
     * @param randomNonceStr 随机数
     * @param orderId        订单号
     * @param orderType      产品类型
     */
    private String unifiedOrder(String openId, String clientIP, String randomNonceStr, String orderId, String orderType) {

        try {

            String url = WxConstant.URL_UNIFIED_ORDER;
            PayInfo payInfo = createPayInfo(openId, clientIP, randomNonceStr, orderId, orderType);
            String md5 = getSign(payInfo);
            payInfo.setSign(md5);

            log.error("md5 value: " + md5);
            //对象转xml
            String xml = WxCommon.payInfoToXMLNew(payInfo);
            log.error(xml);
            System.out.println("统一下单请求体:" + xml);
            StringBuffer buffer = HttpUtil.httpsRequest(url, "POST", xml);
            System.out.println("统一下单请求结果:" + buffer.toString());
            log.error("unifiedOrder request return body: \n" + buffer.toString());
            System.out.println("unifiedOrder request return body: \n" + buffer.toString());
            Map<String, String> result = WxCommon.parseXml(buffer.toString());


            String return_code = result.get("return_code");
            if (StringUtils.isNotBlank(return_code) && return_code.equals("SUCCESS")) {

                String return_msg = result.get("return_msg");
                if (StringUtils.isNotBlank(return_msg) && !return_msg.equals("OK")) {
                    //log.error("统一下单错误！");
                    return "";
                }
                System.out.println("----------微信统一下单id：" + result.get("prepay_id"));
                //保存统一下单信息
                String payInfoId = getUUID();
                payInfo.setId(payInfoId);
                wxPayService.savePayInfo(payInfo);

                //更新订单信息
                switch (orderType) {
                    case Constants.ORDER_TYPE_SCENE:

                        SceneOrder sceneOrder = new SceneOrder();
                        sceneOrder.setId(orderId);
                        //更新订单统一下单id
                        sceneOrder.setWxPrepayId(result.get("prepay_id"));
                        sceneOrder.setPayInfoId(payInfoId);

                        sceneOrderService.updateOrder(sceneOrder);

                        break;
                    case Constants.ORDER_TYPE_HOTEL:

                        HotelOrder hotelOrder = new HotelOrder();
                        hotelOrder.setId(orderId);
                        hotelOrder.setWxPrepayId(result.get("prepay_id"));
                        hotelOrder.setPayInfoId(payInfoId);

                        hotelOrderService.updateOrder(hotelOrder);
                        break;
                    case Constants.ORDER_TYPE_TOUR:

                        TourRouteOrder tourRouteOrder = new TourRouteOrder();
                        tourRouteOrder.setId(orderId);
                        tourRouteOrder.setWxPrepayId(result.get("prepay_id"));
                        tourRouteOrder.setPayInfoId(payInfoId);

                        tourRouteOrderService.update(tourRouteOrder);
                        break;
                    default:
                        break;
                }


                return result.get("prepay_id");

            } else {
                return "";
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }

    private PayInfo createPayInfo(String openId, String clientIP, String randomNonceStr, String orderId, String orderType) {
        Date date = new Date();
        String timeStart = TimeUtils.getFormatTime(date, WxConstant.TIME_FORMAT);
        String timeExpire = TimeUtils.getFormatTime(TimeUtils.addDay(date, WxConstant.TIME_EXPIRE), WxConstant.TIME_FORMAT);

        PayInfo payInfo = new PayInfo();

        payInfo.setAppid(WxConstant.APP_ID);
        payInfo.setMch_id(WxConstant.MCH_ID);
        payInfo.setDevice_info("WEB");
        payInfo.setNonce_str(randomNonceStr);
        //默认即为MD5
        payInfo.setSign_type("MD5");
        System.out.println("设置商家交易数据:" + orderType);
        payInfo.setAttach(orderType);
        //TODO yangpeng set payinfo body
        payInfo.setBody("qjfg-travelsale");
        payInfo.setOut_trade_no(orderId);
        //单位为分
        BigDecimal totalFee = null;
        switch (orderType) {
            case Constants.ORDER_TYPE_HOTEL:
                totalFee = hotelOrderService.getById(orderId).getPrice();
                break;
            case Constants.ORDER_TYPE_SCENE:
                totalFee = sceneOrderService.getById(orderId).getPrice();
                break;
            default:
                TourRouteOrder t = tourRouteOrderService.getById(orderId);
                totalFee = t.getPrice();
                //如果需要发票，加上邮费
                if ("1".equals(t.getNeedBill())) {
                    Dictionary dictionary = dictionaryService.getDicByKeyNo(Constants.DEFALUT_TRANS_FEE).get(0);
                    BigDecimal transFee = new BigDecimal(dictionary.getKeyValue());
                    totalFee = totalFee.add(transFee);
                }
                break;
        }
        int total = totalFee.multiply(new BigDecimal("100")).intValue();
        System.out.println("订单价格为：" + total + "分");
        payInfo.setTotal_fee(total);
        payInfo.setSpbill_create_ip(clientIP);
        payInfo.setTime_start(timeStart);
        payInfo.setTime_expire(timeExpire);
        payInfo.setNotify_url(WxConstant.URL_NOTIFY);
        //交易类型，固定JSAPI
        payInfo.setTrade_type("JSAPI");
//        payInfo.setLimit_pay("no_credit");
        payInfo.setOpenid(openId);
        return payInfo;
    }

    private String getSign(PayInfo payInfo) throws Exception {
        //appid
        //attach
        //body
        //device_info
        //limit_pay
        //mch_id
        //nonce_str
        //notify_url
        //openid
        //out_trade_no
        //sign_type
        //spbill_create_ip
        //time_expire
        //time_start
        //total_fee
        //trade_type
        StringBuilder sb = new StringBuilder();
        sb.append("appid=").append(payInfo.getAppid())
                .append("&attach=").append(payInfo.getAttach())
                .append("&body=").append(payInfo.getBody())
                .append("&device_info=").append(payInfo.getDevice_info())
//                .append("&limit_pay=").append(payInfo.getLimit_pay())
                .append("&mch_id=").append(payInfo.getMch_id())
                .append("&nonce_str=").append(payInfo.getNonce_str())
                .append("&notify_url=").append(payInfo.getNotify_url())
                .append("&openid=").append(payInfo.getOpenid())
                .append("&out_trade_no=").append(payInfo.getOut_trade_no())
                .append("&sign_type=").append(payInfo.getSign_type())
                .append("&spbill_create_ip=").append(payInfo.getSpbill_create_ip())
                .append("&time_expire=").append(payInfo.getTime_expire())
                .append("&time_start=").append(payInfo.getTime_start())
                .append("&total_fee=").append(payInfo.getTotal_fee())
                .append("&trade_type=").append(payInfo.getTrade_type())
                .append("&key=" + WxConstant.APP_KEY);

        log.error("排序后的拼接参数：" + sb.toString());

        return WxCommon.getMD5(sb.toString().trim()).toUpperCase();
    }

    @RequestMapping("/payBack")
    @ResponseBody
    public String notify(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        synchronized (this) {
            System.out.println("微信来消息了");
            String result;//返回给微信的处理结果
            String inputLine;
            String notityXml = "";
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Access-Control-Allow-Origin", "*");
            //微信给返回的东西
            try {
                while ((inputLine = request.getReader().readLine()) != null) {
                    notityXml += inputLine;
                }
                request.getReader().close();
            } catch (Exception e) {
                System.out.println("xml获取失败");
                e.printStackTrace();
                result = setXml("fail", "xml获取失败");
            }
            if (StringUtils.isEmpty(notityXml)) {
                result = setXml("fail", "xml为空");
                System.out.println("xml为空");
            }
            Map<String, String> map = WxCommon.parseXml(notityXml);
            PayBack payBack = new PayBack();
            if ("SUCCESS".equals(map.get("return_code"))) {
                //通信成功，进行签名校验 解析各种数据
                //应用ID
                String appid = map.get("appid");
                payBack.setId(getUUID());
                payBack.setAppid(appid);
                //商家数据包
                String attach = map.get("attach");
                payBack.setAttach(attach);
                //付款银行
                String bank_type = map.get("bank_type");
                payBack.setBankType(bank_type);
                //现金支付金额
                String cash_fee = map.get("cash_fee");
                payBack.setCashFee(cash_fee);
                //货币种类
                String fee_type = map.get("fee_type");
                payBack.setFeeType(fee_type);
                //是否关注公众账号
                String is_subscribe = map.get("is_subscribe");
                payBack.setIsSubscribe(is_subscribe);
                //商户号
                String mch_id = map.get("mch_id");
                payBack.setMchId(mch_id);
                //随机字符串
                String nonce_str = map.get("nonce_str");
                payBack.setNonceStr(nonce_str);
                //用户标识
                String openid = map.get("openid");
                payBack.setOpenid(openid);
                // 获取商户订单号
                String out_trade_no = map.get("out_trade_no");
                payBack.setOutTradeNo(out_trade_no);
                // 业务结果
                String result_code = map.get("result_code");
                payBack.setResultCode(result_code);
                // SUCCESS/FAIL
                String return_code = map.get("return_code");
                payBack.setReturnCode(return_code);
                // 获取签名
                String sign = map.get("sign");
                payBack.setSign(sign);
                //支付完成时间
                String time_end = map.get("time_end");
                payBack.setTimeEnd(time_end);
                // 获取订单金额
                String total_fee = map.get("total_fee");
                payBack.setTotalFee(total_fee);
                //交易类型
                String trade_type = map.get("trade_type");
                payBack.setTradeType(trade_type);
                //微信交易单号
                String transaction_id = map.get("transaction_id");
                payBack.setTransactionId(transaction_id);

                SortedMap<String, String> parameters = new TreeMap<String, String>();
                // 数据加密
                //应用ID
                parameters.put("appid", appid);
                //商家数据包
                parameters.put("attach", attach);
                //付款银行
                parameters.put("bank_type", bank_type);
                //现金支付金额
                parameters.put("cash_fee", cash_fee);
                //货币种类
                parameters.put("fee_type", fee_type);
                //是否关注公众账号
                parameters.put("is_subscribe", is_subscribe);
                //商户号
                parameters.put("mch_id", mch_id);
                //随机字符串
                parameters.put("nonce_str", nonce_str);
                //用户标识
                parameters.put("openid", openid);
                // 商户订单号
                parameters.put("out_trade_no", out_trade_no);
                // 业务结果
                parameters.put("result_code", result_code);
                // SUCCESS/FAIL
                parameters.put("return_code", return_code);
                // 支付完成时间
                parameters.put("time_end", time_end);
                // 获取订单金额
                parameters.put("total_fee", total_fee);
                //交易类型
                parameters.put("trade_type", trade_type);
                //微信交易单号
                parameters.put("transaction_id", trade_type);
                //加密前验证notify支付订单网关---https://gw.tenpay.com/gateway/simpleverifynotifyid.xml
                //MD5加密
                String endsign = WxCommon.createSign(parameters, WxConstant.APP_KEY);
                System.out.println("**************************************************************************************************");
                System.out.println(appid + "-------------------应用ID");
                System.out.println(attach + "-------------------商家数据包");
                System.out.println(bank_type + "-------------------付款银行");
                System.out.println(cash_fee + "-------------------现金支付金额");
                System.out.println(fee_type + "-------------------货币种类");
                System.out.println(is_subscribe + "-------------------是否关注公众账号");
                System.out.println(mch_id + "-------------------商户号");
                System.out.println(nonce_str + "-------------------随机字符串");
                System.out.println(openid + "-------------------用户标识");
                System.out.println(out_trade_no + "-------------------获取商户订单号");
                System.out.println(result_code + "-------------------业务结果");
                System.out.println(return_code + "------------------- SUCCESS/FAIL");
                System.out.println(sign + "-------------------获取签名-微信回调的签名");
                System.out.println(time_end + "-------------------支付完成时间");
                System.out.println(total_fee + "-------------------获取订单金额");
                System.out.println(trade_type + "-------------------交易类型");
                System.out.println(transaction_id + "-------------------微信支付订单号");
                System.out.println(endsign + "-------------------第二次加密sign");
                System.out.println("**************************************************************************************************");
                // TODO yangpeng验证签名
//                if (sign.equals(endsign)) {
                if (true) {
                    //签名校验成功，返回通信成功标识
                    result = setXml("SUCCESS", "OK");
                    //业务开始,校验交易号,如果系统已有该交易信息，则表示重复消息，如果没有该交易信息，进行保存
                    PayBack payBack1 = wxPayService.selectByTrasactionId(transaction_id);
                    if (!ValidUtil.isEmpty(payBack1)) {
                        return result;
                    }
                    try {
                        wxPayService.savePayBack(payBack);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw e;
                    }

                    //TODO yangpeng
                    if ("SUCCESS".equals(result_code)) {
                        String name = "";
                        String telephone = "";
                        String time = "";
                        String typeName = "";
                        //交易成功
                        Map priceAndCost = null;
                        switch (attach) {
                            case Constants.ORDER_TYPE_SCENE:
                                SceneOrder sceneOrder = new SceneOrder();
                                sceneOrder.setId(out_trade_no);
                                sceneOrder.setTransactionId(transaction_id);
                                //更改订单状态为已支付
                                sceneOrder.setStatus(Constants.ORDER_STATUS_PAYED);
                                sceneOrderService.updateOrder(sceneOrder);
                                //发短信
                                // SmsSingleSender ssender = new SmsSingleSender(smsAppid, smsAppkey);
//                                SmsSingleSenderResult result = ssender.send(0, "86", phoneNumbers[0],
//                                        "【腾讯云】您的验证码是: 5678", "", "");
                                name = sceneOrder.getRealName();
                                Map map3 = new HashMap<String, Object>();
                                map3.put("id", sceneOrder.getId());
                                List<Map> list3 = sceneOrderService.getByParam(map3);
                                if (list3 != null && list3.size() > 0) {
                                    if (!ValidUtil.isEmpty(list3.get(0).get("real_name"))) {
                                        name = list3.get(0).get("real_name").toString();

                                    }
                                    if (!ValidUtil.isEmpty(list3.get(0).get("noticePhone"))) {
                                        telephone = list3.get(0).get("noticePhone").toString();
                                    }
                                    if (!ValidUtil.isEmpty(list3.get(0).get("useDate"))) {
                                        time = list3.get(0).get("useDate").toString();
                                    }
                                    typeName = list3.get(0).get("scene_name").toString();
                                    sendOrderMsg(name, telephone, time, typeName);
                                }
                                break;
                            case Constants.ORDER_TYPE_HOTEL:
                                HotelOrder hotelOrder = new HotelOrder();
                                hotelOrder.setId(out_trade_no);
                                hotelOrder.setTransactionId(transaction_id);
                                //更改订单状态为已支付
                                hotelOrder.setStatus(Constants.ORDER_STATUS_PAYED);
                                hotelOrderService.updateOrder(hotelOrder);
//
                                Map map2 = new HashMap<String, Object>();
                                map2.put("id", hotelOrder.getId());
                                List<Map> list = hotelOrderService.selectByParam(map2);
                                if (list != null && list.size() > 0) {
                                    if (!ValidUtil.isEmpty(list.get(0).get("real_name"))) {
                                        name = list.get(0).get("real_name").toString();
                                    }
                                    if (!ValidUtil.isEmpty(list.get(0).get("noticePhone"))) {
                                        telephone = list.get(0).get("noticePhone").toString();
                                    }
                                    if (!ValidUtil.isEmpty(list.get(0).get("useDate"))) {
                                        time = list.get(0).get("useDate").toString();
                                    }
                                    typeName = list.get(0).get("hotelName").toString();
                                    sendOrderMsg(name, telephone, time, typeName);
                                }
                                break;
                            case Constants.ORDER_TYPE_TOUR:
                                // 旅游线路
                                typeName = "旅游";
                                TourRouteOrder tourRouteOrder = new TourRouteOrder();
                                tourRouteOrder.setId(out_trade_no);
                                tourRouteOrder.setTransactionId(transaction_id);
                                //修改订单状态为已支付
                                tourRouteOrder.setStatus(Constants.ORDER_STATUS_PAYED);
                                tourRouteOrderService.update(tourRouteOrder);
                                Map map4 = new HashMap<String, Object>();
                                map4.put("id", tourRouteOrder.getId());
                                List<Map> list2 = tourRouteOrderService.queryByParams(map4);
                                if (list2 != null && list2.size() > 0) {
                                    if (!ValidUtil.isEmpty(list2.get(0).get("customer_name"))) {
                                        name = list2.get(0).get("customer_name").toString();
                                    }
                                    if (!ValidUtil.isEmpty(list2.get(0).get("noticePhone"))) {
                                        telephone = list2.get(0).get("noticePhone").toString();
                                    }
                                    if (!ValidUtil.isEmpty(list2.get(0).get("inTime"))) {
                                        time = list2.get(0).get("inTime").toString();
                                    }
                                    typeName=list2.get(0).get("routeName").toString();
                                    sendOrderMsg(name, telephone, time, typeName);
                                }

                            default:
                                break;
                        }
                        //查询该订单
                        //out_trade_no
                        System.out.println("交易成功！");
                    } else {
                        //交易失败
                        String err_code = map.get("err_code");
                        String err_code_des = map.get("err_code_des");
                        System.out.println("交易失败");
                        System.out.println("err_code:" + err_code + ",err_code_des:" + err_code_des);
                        switch (attach) {
                            case Constants.ORDER_TYPE_SCENE:
                                SceneOrder sceneOrder = new SceneOrder();
                                sceneOrder.setId(out_trade_no);
                                sceneOrder.setTransactionId(transaction_id);
                                //更改订单状态为交易失败
                                sceneOrder.setStatus(Constants.ORDER_STATUS_FAIL);
                                sceneOrderService.updateOrder(sceneOrder);
                                break;
                            case Constants.ORDER_TYPE_HOTEL:
                                HotelOrder hotelOrder = new HotelOrder();
                                hotelOrder.setId(out_trade_no);
                                hotelOrder.setTransactionId(transaction_id);
                                //更改订单状态为交易失败
                                hotelOrder.setStatus(Constants.ORDER_STATUS_FAIL);
                                hotelOrderService.updateOrder(hotelOrder);
                                break;
                            case Constants.ORDER_TYPE_TOUR:
                                // 旅游线路
                                TourRouteOrder tourRouteOrder = new TourRouteOrder();
                                tourRouteOrder.setId(out_trade_no);
                                tourRouteOrder.setTransactionId(transaction_id);
                                //修改订单状态为交易失败
                                tourRouteOrder.setStatus(Constants.ORDER_STATUS_FAIL);
                                tourRouteOrderService.update(tourRouteOrder);
                            default:
                                break;
                        }
                    }

                } else {
                    System.err.println("签名不一致！");
                    result = setXml("fail", "签名不一致！");
                }
            } else {
                System.err.println("微信返回的通信错误");
                System.out.println(map.get("return_msg") + "----------------错误信息");
                result = setXml("fail", "微信返回的交易状态不正确（result_code=" + "SUCCESS" + "）");
            }
            response.getWriter().write(result);
            response.getWriter().flush();
            System.out.println("回调成功");
            System.out.println("----返回给微信的xml：" + result);
            return result;
        }

    }

    private void sendOrderMsg(String name, String telephone, String time, String typeName) {
        ArrayList<String> smsParams = new ArrayList<>();
        Integer smsId = Integer.valueOf(dictionaryService.getDicByKeyNo("NEW_ORDER").get(0).getCaption());
        if (!ValidUtil.isEmpty(name) && !ValidUtil.isEmpty(time) && !ValidUtil.isEmpty(telephone)) {
            smsParams.add(name);
            smsParams.add(time);
            smsParams.add(typeName);
            refundService.sendOrderSms(telephone, smsId, smsParams);
        }
    }

    //通过xml 发给微信消息
    public static String setXml(String return_code, String return_msg) {
        SortedMap<String, String> parameters = new TreeMap<String, String>();
        parameters.put("return_code", return_code);
        parameters.put("return_msg", return_msg);
        return "<xml><return_code><![CDATA[" + return_code + "]]>" +
                "</return_code><return_msg><![CDATA[" + return_msg + "]]></return_msg></xml>";
    }
}


















